<?php

namespace App\Imports;

use App\Models\Goods;
use Maatwebsite\Excel\Concerns\ToModel;

class GoodsImport implements ToModel
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function model(array $row)
    {
        if ($row[0] == '淘宝订单' || !$row[6])
        {
            return;
        }
         // dd($row);
        // Log::info($row[17]);
        $goods = Goods::where('goods_bn', $row[6])->first();

        if (!$goods)
        {
            return new Goods([
                'goods_bn' => $row[6],
                'goods_name' => $row[2],
            ]);
        }
        else
        {
            $goods->update([
                'goods_bn' => $row[6],
                'goods_name' => $row[2],
                'updated_at' => date('Y-m-d H:i:s')
            ]);
        }
    }

    //批量导入1000条
    public function batchSize(): int
    {
        return 1000;
    }
    //以1000条数据基准切割数据
    public function chunkSize(): int
    {
        return 1000;
    }
}
